package org.yray.sip.handler.flow;


import lombok.extern.slf4j.Slf4j;
import org.yray.sip.base.MsgEle;
import org.yray.sip.base.SipMsg;
import org.yray.sip.constant.SipCodeEnum;
import org.yray.sip.handler.MessageHandler;
import org.yray.sip.rtp.sender.ISipSessionCache;
import org.yray.sip.server.SipServerContext;
import org.yray.sip.server.SipSession;
import org.yray.sip.utils.IcspBeanHolder;

import java.util.Optional;

@Slf4j
public class Ringing180Handler extends MessageHandler {




    @Override
    public String[] handler(SipMsg sipMsg, SipServerContext ssc) {
            //这里需要区别下是机器人的还是转人工的
            String callId= Optional.ofNullable(sipMsg.getMsgLine(MsgEle.CALL_ID)).map(String::trim).orElse(null);
            SipSession sipSession= IcspBeanHolder.getBean(ISipSessionCache.class).get(callId);
            Optional.ofNullable(sipSession).orElse(new SipSession(sipMsg,ssc.getRunIp(),ssc.getRunPort(),false));
            getEventFactory().sipEvent(callId, SipCodeEnum.SIP_183);
            return BLANK_STRINGS;
        }
}
